<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/28 0028
 * Time: 下午 3:49
 */

//首页功能
//加载公共文件
include_once './public/public.php';

//调用数据库初始化文件，从数据表获取所有的学生信息

//加载mysql的初始文件
include_once './public/mysql.php';

//获取分页相关信息
//获取页码
$page = isset($_GET['page'])?$_GET['page']:1;

//设定每页显示的数据量
$length = 1;

//求出分页偏移量
$offset = ($page -1) * $length;

//获取总页数
$sql = 'select count(*) as c from pmt_student as s left join pmt_class as c on s.class_id = c.id ';
$res = my_error($sql);
$count = mysql_fetch_assoc($res);
$counts = $count['c'];

//总页数
$pages = ceil($counts/$length);

//求出上一页和下一页对应的页码
$prev = $page > 1 ? $page-1 : 1;
$next = $page < $pages ? $page+1 : $pages;




//组织sql语句查询所有学生信息
$sql = "select s.* ,c.name as c_name ,c.room from pmt_student as s left join pmt_class as c on s.class_id = c.id limit {$offset},{$length} ";

//执行
$res = my_error($sql);

//取出所有数据
$students = array();
while ($row = mysql_fetch_assoc($res)){
    $students[] = $row;
}

//加载模板显示数据
include_once './templates/index.html';